<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="java.util.*"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ request.getContextPath() + "/";
//response.sendRedirect("common/login");
%>
<c:set var="path" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>StuList</title>
			<script type="text/javascript" src="${path }/resource/js/jquery-1.8.3.min.js"></script>
			<script type="text/javascript" src="${path }/resource/js/mytools.js"></script>
			<%-- <script type="text/javascript" src="${path }/resource/layer/layer.js"></script> --%>
			<script type="text/javascript" src="${path }/resource/layui/layui.js" ></script>
			<link rel="stylesheet" href="${path }/resource/layui/css/layui.css" />
	</head>
	<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>普通表单</legend>
</fieldset>
 
<form class="layui-form" id="searchFrom">
  <div class="layui-form-item" >
    <div class="layui-inline">
      <label class="layui-form-label">id</label>
      <div class="layui-input-inline">
        <input type="text" name="id"  autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label">姓名</label>
      <div class="layui-input-inline">
        <input type="text" name="name" id="date" placeholder="姓名" autocomplete="off" class="layui-input" >
      </div>
    </div>
  </div>
  <div class="layui-form-item" pane="">
    <div class="layui-input-block">
      <input type="button" class="layui-btn layui-btn-small" onclick="mjs.search()" value='搜索'>
      <input type="reset" class="layui-btn layui-btn-primary layui-btn-small" value='重置'>
      <input type="button" value="新增" onclick="mjs.editFrom()" class="layui-btn layui-btn-small"/>
      <input type="button" value="批量删除" onclick="dels()" class="layui-btn layui-btn-danger layui-btn-small" />
    </div>
       </div>
      <div class="layui-form-item" >
   
      </div>
     
</form>
<div class="layui-form">
	<div id="tablediv">
	<table id="table1" class="layui-table">
	<thead id="thead">
	 <tr>
		<th data-name = "id" data-format="check"><input type='checkbox' name='id' lay-skin='primary' lay-filter='allChoose' /></th>
		<th data-name = "name" >name</th> 
		<th data-name = "name">name</th> 
		<th data-name = "name">name</th> 
		<th data-name = "name">name</th> 
		<th data-name = "name">name</th> 
		<th data-name = "name">name</th> 
		<th data-name = "id" data-format="operation" style="width:80px;">操作</th>  
		 </tr>
	</thead>
	</table>
	</div>
	</div>
	<script>
	  var form;
	  var layer;
	  var layedit; 
	  var laydate;
	var mjs =	mytooljs.initTable({  
		idSelecter:"#table1",
		sendurl:"${path}/user/test/Stu/showList" , //求数据的地址
		pagesize:5,//分页大小
		title:"学生信息",//弹出页展示标题
		delUrl:"${path}/user/test/Stu/del",//删除数据地址
		editUrl:"${path}/user/test/Stu/editForm" //打开编辑或新增页面地址
		});
	
	//操作
	function check(id,index){
		var html = "<input type='checkbox' name='id' lay-skin='primary' value='"+id+"'/>"
		return html;
	}
	
	function operation(id,index){
		var html = "<div class='layui-btn-group'>";
		html+=
			 " <button class='layui-btn layui-btn-small layui-btn-primary' onclick='mjs.editFrom("+ id + ")' >"
			+" <i class='layui-icon'>&#xe642;</i>"
			+" </button>";
		html+= 
			 " <button class='layui-btn layui-btn-small layui-btn-primary' onclick='mjs.delRec("+ id + ")' >"
			+" <i class='layui-icon'>&#xe640;</i>"
			+" </button>"
		    +"</div>";
		return html;
	}
	layui.use(['form', 'layedit', 'laydate'], function(){
		  form = layui.form();
		  layer = layui.layer;
		  layedit = layui.layedit;
		  laydate = layui.laydate;
		  
	/* 	  //创建一个编辑器
		  var editIndex = layedit.build('LAY_demo_editor');
		 
		  //自定义验证规则
		  form.verify({
		    title: function(value){
		      if(value.length < 5){
		        return '标题至少得5个字符啊';
		      }
		    }
		    ,pass: [/(.+){6,12}$/, '密码必须6到12位']
		    ,content: function(value){
		      layedit.sync(editIndex);
		    }
		  }); */
		  
		/*   //监听指定开关
		  form.on('switch(switchTest)', function(data){
		    layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
		      offset: '6px'
		    });
		    layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
		  });
		  
		  //监听提交
		  form.on('submit(demo1)', function(data){
		    layer.alert(JSON.stringify(data.field), {
		      title: '最终的提交信息'
		    })
		    return false;
		  }); */
		  form.on('checkbox(allChoose)', function(data){
			    var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
			    child.each(function(index, item){
			      item.checked = data.elem.checked;
			    });
			    form.render('checkbox');
			  });
		});
	function dels(){
		var durl = '${path}/user/test/Stu/dels';
		var ids=[];
		var idsStr='';
		var child = $('table').find('tbody input[type="checkbox"]');
	    child.each(function(index, item){
	    	if(item.checked){
	    		ids.push(item.value);
	    	}
	    });
	    if(ids.length<1){
	    	layer.alert("你一条也没选中");
	    }
	    idsStr= ids.join(",");
	    layer.alert(idsStr);
		layer.open({
	       	  content: '你确定要删除'+idsStr
	       	  ,btn: ['确定','取消']
	       	  ,yes: function(){
	       		layer.alert("删除成功");
	       		 $.ajax({
			  		'type':'post',
			  		'url':durl,
			  		'data':{"ids":ids},
			  		'dataType':'json',
			  		'success':function(data,status){
			  			layer.alert("删除成功");
			  			table.refCurr();//重新加载当前页
			  		}
			  	}); 
	       	  },btn2:function(){
	       		layer.closeAll();
	       	  } ,cancel:function(){
	       		layer.closeAll();
			}
	       	}); 
	}
	</script>
	</body>
</html>
